package com.im.service.user.controller;

import com.im.common.model.RestResponse;
import com.im.service.user.entity.ImUserDataEntity;
import com.im.service.user.model.param.GetUserInfoParam;
import com.im.service.user.model.param.ModifyUserInfoParam;
import com.im.service.user.model.param.UserIdParam;
import com.im.service.user.model.result.GetUserInfoResult;
import com.im.service.user.service.ImUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(tags = "用户数据控制器")
@RestController
@RequestMapping("/v1/user/data")
public class UserDataController {

    @Autowired
    ImUserService userService;

    @PostMapping("/getUserInfo")
    @ApiOperation(value = "获取用户信息", notes = "根据用户 ID 和应用 ID 获取用户信息")
    public RestResponse getUserInfo(@RequestBody @Valid GetUserInfoParam param, Integer appId) {
        param.setAppId(appId);
        GetUserInfoResult userInfo = userService.getUserInfo(param);
        return RestResponse.success(userInfo);
    }

    @PostMapping("/getSingleUserInfo")
    @ApiOperation(value = "获取单个用户信息", notes = "根据用户 ID 和应用 ID 获取单个用户信息")
    public RestResponse getSingleUserInfo(@RequestBody @Validated UserIdParam param, Integer appId) {
        param.setAppId(appId);
        ImUserDataEntity userInfo = userService.getSingleUserInfo(param.getUserId(), param.getAppId());
        return RestResponse.success(userInfo);
    }

    @PostMapping("/modifyUserInfo")
    @ApiOperation(value = "修改用户信息", notes = "根据用户 ID 和应用 ID 修改用户信息")
    public RestResponse modifyUserInfo(@RequestBody @Validated ModifyUserInfoParam param, Integer appId) {
        param.setAppId(appId);
        userService.modifyUserInfo(param);
        return RestResponse.success();
    }
}
